package models

import (
	"gorm.io/gorm"
	"school/user-srv/basic/config"
)

type Admin struct {
	gorm.Model
	Username string `gorm:"type:varchar(25);unique;comment:'账号'"`
	Password string `gorm:"type:varchar(32);comment:'密码'"`
	Mobile   string `gorm:"type:varchar(11);unique;comment:'联系方式'"`
}
type School struct {
	gorm.Model
	Name    string `gorm:"type:varchar(30);comment:'校区名称'"`
	Address string `gorm:"type:varchar(35);comment:'地址'"`
	Static  string `gorm:"type:varchar(20);comment:'状态'"`
	Contact string `gorm:"type:varchar(25);comment:'联系人'"`
	Phone   string `gorm:"type:varchar(11);comment:'联系人电话'"`
}
type AdminSchool struct {
	AdminId  int `gorm:"type:int(10);comment:'管理员ID'"`
	SchoolId int `gorm:"type:int(10);comment:'学校ID'"`
}

func Login[T any](data *T) error {
	return config.DB.Find(&data).Error
}

func SchoolAdd[T any](data *T) error {
	return config.DB.Create(&data).Error
}
func SchoolList[T any](date *[]T, size, page int, name string) error {
	switch {
	case size > 100:
		size = 100
	case size <= 0:
		size = 10
	}
	offset := (page - 1) * size
	return config.DB.Offset(offset).Limit(size).
		Where("name like ?", "%"+name+"%").
		Order("created_at desc").Find(&date).Error
}
func AdminList[T any](date *T, mobile string) error {
	return config.DB.Where("mobile=?", mobile).Find(&date).Error
}
